# populistparties.R
# Outputs: List of populist parties in appendix
# Dependencies: master.csv

library(readr)
library(dplyr)
library(xtable)

setwd('')

df <- read_csv('master.csv')

# List of populist parties (left and right) ------------------------------------

table_lr <-
  df %>% filter(populist == TRUE, election_type == 'parliament') %>%
  select(country_name, party_name_english, family_name, election_year) %>%
  # print(n = nrow(.))
  group_by(country_name, party_name_english, family_name) %>%
  summarise(election_year = paste(election_year, collapse = ', ')) %>%
  arrange(country_name, party_name_english) %>%

names(table_lr) <- c('Country', 'Party', 'Family', 'Election Years')

table_lr$Family[which(table_lr$Family == 'Communist/Socialist')] <-
  'Communist/ Socialist'


xtab_lr <- xtable(table_lr)

# HTML
print(xtab_lr, type = 'html', file = 'tables/t_populistparties_lr.html',
      include.rownames = F)

# LaTeX
print(xtab_lr, type = 'latex', file = 'tables/t_populistparties_lr.tex',
      include.rownames = F, only.contents = T, booktabs = T)